<?php
namespace app\admin\model;
use think\Config;
use think\Db;
class ContentModel extends \app\common\model\CommonModel
{
    
    /**
     * @param int       $data['type']
     * @param int       $data['toolid']
     * @param string    $data['content']
     */
    public function edit($data)
    {
        try {
            if(Db::table('content')->where(['type' => $data['type'],'toolid' => $data['toolid']])->find()){
                Db::table('content')->where(['type' => $data['type'],'toolid' => $data['toolid']])->update([
                    'content'   => $data['content']
                ]);
                return true;
            }
            Db::table('content')->insert([
                'type'      => (int)$data['type'],    
                'toolid'    => (int)$data['toolid'],    
                'content'   => $data['content'],    
            ]);
            return true;        
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage());
        }
    }

    /**
     * @param int       $data['type']
     * @param int       $data['toolid']
     */
    public function info($data)
    {
        try {
            return Db::table('content')->where(['type' => $data['type'],'toolid' => $data['toolid']])->find();     
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage());
        }    
    }
}